﻿#include <iostream>
#include <cassert>
using namespace std;

class Product
{
public:
    Product()
    {
        cout << "Product ..." << endl;
    };
};

class Builder {
public:
    virtual void BuildPartA() = 0;
    virtual void BuildPartB() = 0;
    virtual void BuildPartC() = 0;
    virtual Product* GetProduct() = 0;
    virtual ~Builder() { }
};

class ConcreteBuild :public Builder
{
public:
    void BuildPartA()
    {
        cout << "Build Part A" << endl;
    }

    void BuildPartB()
    {
        cout << "Build Part B" << endl;
    }

    void BuildPartC()
    {
        cout << "Build Part C" << endl;
    }

    Product* GetProduct()
    {
        return new Product;
    }
};

class Director
{
public :
    Director(Builder *builder){
        m_pbuilder = builder;
    }

    void Construct()
    {
        assert(m_pbuilder != nullptr);

        m_pbuilder->BuildPartA();
        m_pbuilder->BuildPartB();
        m_pbuilder->BuildPartC();
    }

private:
    Builder* m_pbuilder;
};

int main()
{
	auto builder = new ConcreteBuild();
    assert(builder != nullptr);

    auto director = new Director(builder);
    assert(director != nullptr);

    director->Construct();

    Product* product = builder->GetProduct();
    assert(product != nullptr);

    delete product;
    delete director;
    delete builder;

	return 0;
}
